package com.kexio.pay.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 银联支付配置属性
 * 
 * 配置文件: application-pay.yml
 * 
 * @author Kexio Team
 */
@Component
@ConfigurationProperties(prefix = "unionpay")
public class UnionPayProperties {
    
    /**
     * 商户号
     */
    private String mchId;
    
    /**
     * API密钥
     */
    private String apiKey;
    
    /**
     * 前台通知地址
     */
    private String frontUrl;
    
    /**
     * 后台通知地址
     */
    private String backUrl;
    
    /**
     * 签名证书路径
     */
    private String signCertPath;
    
    /**
     * 签名证书密码
     */
    private String signCertPwd;
    
    /**
     * 验签证书目录
     */
    private String validateCertDir;
    
    /**
     * 是否测试环境
     */
    private boolean testMode = true;
    
    /**
     * 服务器URL
     */
    private String serverUrl;

    // Getters and Setters
    public String getMchId() {
        return mchId;
    }

    public void setMchId(String mchId) {
        this.mchId = mchId;
    }

    public String getApiKey() {
        return apiKey;
    }

    public void setApiKey(String apiKey) {
        this.apiKey = apiKey;
    }

    public String getFrontUrl() {
        return frontUrl;
    }

    public void setFrontUrl(String frontUrl) {
        this.frontUrl = frontUrl;
    }

    public String getBackUrl() {
        return backUrl;
    }

    public void setBackUrl(String backUrl) {
        this.backUrl = backUrl;
    }

    public String getSignCertPath() {
        return signCertPath;
    }

    public void setSignCertPath(String signCertPath) {
        this.signCertPath = signCertPath;
    }

    public String getSignCertPwd() {
        return signCertPwd;
    }

    public void setSignCertPwd(String signCertPwd) {
        this.signCertPwd = signCertPwd;
    }

    public String getValidateCertDir() {
        return validateCertDir;
    }

    public void setValidateCertDir(String validateCertDir) {
        this.validateCertDir = validateCertDir;
    }

    public boolean isTestMode() {
        return testMode;
    }

    public void setTestMode(boolean testMode) {
        this.testMode = testMode;
    }

    public String getServerUrl() {
        if (serverUrl == null) {
            return testMode 
                ? "https://qr-test2.95516.com/qrcGtwWeb-web/api/mall" 
                : "https://qr.95516.com/qrcGtwWeb-web/api/mall";
        }
        return serverUrl;
    }

    public void setServerUrl(String serverUrl) {
        this.serverUrl = serverUrl;
    }

    @Override
    public String toString() {
        return "UnionPayProperties{" +
                "mchId='" + mchId + '\'' +
                ", testMode=" + testMode +
                ", serverUrl='" + getServerUrl() + '\'' +
                '}';
    }
}

